/* Convert MSIE Favourites to HTML page */ /* Author: Brian D. Jones */ /* Date: 10th Jan 97 */ /* Email: Brian_Jones@technologist.com */ // History: 18 May 97 Check for "URL=" since not always last line in file. // 14 Jun 97 Long names which include blanks now supported. // 26 Jul 97 Explorer 4.0 aware // 13 Oct 97 Explorer 4.0 Outline added. // 20 Nov 99 Change Web site URL. // 26 May 2001 Sort entries. // 26 May 2001 Make like an Applet for use in HTML Application GUI import java.io.*; import java.util.*; import java.applet.*; import java.awt.*; import com.ms.security.*; public class Favorite extends Applet { public static String Version = "1.81"; private static int level = 0; private static void ListDir( File Path , PrintStream Out) { String Names[] = Path.list(); if (folderFirst) sortF(Names, Path); else sort(Names); if (level == 0) Out.println("
"); else Out.println("
"); level = level +1; Out.println("
"); for (int i=0; i < Names.length; i++) { try { File temp = new File( Path, Names[i] ); if ( temp.isDirectory() ) { Out.println( "
"+ temp.getName() +"
" ); ListDir ( temp, Out ); Out.println( "
" ); } else if (temp.getName().endsWith(".url")) { try { String BaseName = temp.getName(); String sURL = null, sDesc = null, sAuthor = null, sWhatsNew = null, sAccessed = null, sModified = null; DataInputStream file = new DataInputStream( new FileInputStream( temp )); String Line= null; Date dateModified = null, dateAccessed = null; while ( file.available() > 0 ) { Line = file.readLine(); // if (Line.startsWith("URL=")) break; // Not always last line. if (Line.startsWith("URL=")) sURL = Line.substring( Line.indexOf( "=" )+1); // These items appeared in the Beta, but don't seem to be in the final version. if (Line.startsWith("Desc=")) sDesc = Line.substring( Line.indexOf( "=" )+1); if (Line.startsWith("Author=")) sAuthor = Line.substring( Line.indexOf( "=" )+1); if (Line.startsWith("WhatsNew=")) sWhatsNew = Line.substring( Line.indexOf( "=" )+1); if (Line.startsWith("Accessed=")) sAccessed = Line.substring( Line.indexOf( "=" )+1); if (Line.startsWith("Modified=")) sModified = Line.substring( Line.indexOf( "=" )+1); } file.close(); // Line = Line.substring( Line.indexOf( "=" )+1); BaseName = BaseName.substring( 0, BaseName.lastIndexOf( "." )); Out.print( "
"); try { if (sModified != null) { String tmp = null; StringTokenizer token = new StringTokenizer( sModified, ",", false ); tmp = token.nextToken().substring(2); dateModified = new Date( Long.parseLong(tmp,16)); // Out.println(" Modified: " +dateModified.toLocaleString()); } if (sAccessed != null) { String tmp = null; StringTokenizer token = new StringTokenizer( sAccessed, ",", false ); tmp = token.nextToken().substring(2); dateAccessed = new Date( Long.parseLong(tmp,16)); // Out.println(" Modified: " +dateAccessed.toLocaleString()); } } catch ( Exception e ) { } // Out.println( "");} Out.print( ""); if ( dateAccessed != null && dateModified != null && dateAccessed.after(dateModified)) Out.print( ""); else Out.print( ""); Out.println( BaseName +""); if (sWhatsNew != null) Out.println("
What's new: " +sWhatsNew +"
"); else if (sDesc != null ) Out.println("
" +sDesc +"
"); } catch ( Exception e ) { ; } } else if (temp.getName().equalsIgnoreCase("desktop.ini")) { try { String BaseName = Path.getName(); String sURL = null, sLogo = "" + iconPath +"url.gif", sWideLogo = null; DataInputStream file = new DataInputStream( new FileInputStream( temp )); String Line= null; while ( file.available() > 0 ) { Line = file.readLine(); // if (Line.startsWith("URL=")) break; // Not always last line. if (Line.startsWith("CDFURL=")) sURL = Line.substring( Line.indexOf( "=" )+1); if (Line.startsWith("Logo=")) sLogo = Line.substring( Line.indexOf( "=" )+1); if (Line.startsWith("WideLogo=")) sWideLogo = Line.substring( Line.indexOf( "=" )+1); } file.close(); if (sURL != null) { Out.print( ""); if (sWideLogo != null) Out.print( ""); else Out.print( ""); } } catch ( Exception e ) { ; } } } catch ( Exception e ) { continue; } } Out.println("

"); Out.println("
"); } public static void DoIt( String Path, PrintStream Out ) { File Root = null; try { Root = new File( Path ); } catch ( Exception e ) { Out.println("404 Not Given"); Out.println("

404 Not Given

No path was requested.

"); return; } if ( !Root.exists() || !Root.isDirectory()) { Out.println("404 Not Found"); Out.println("

404 Not Found

The requested path " +Path +" was not found on this server

"); return; } Out.print( ""); Out.println( "" +Root.getName() +""); Out.println(""); Out.println( ""); Out.println( "" ); Out.print(""); Out.println( "

" +Root.getName() +"

"); ListDir( Root, Out ); Out.println( "
" ); Out.println( "Created: " +new Date().toLocaleString() ); Out.println( "using Java application v: " + Version + " created by Brian D. Jones" ); Out.println( "Email: Brian_Jones@technologist.com" ); Out.println( "" ); Out.println( "" ); } private static String cmdLine( String args[]) { String returnString = args[0]; for ( int i=1; i< args.length; i++) returnString = returnString +" " +args[i]; return returnString; } private static boolean folderFirst = false; private static String iconPath = "/icons/"; private static void sort( String toSort[]) { if (toSort.length<2) return; int i,j; for (i=0; i < toSort.length ; i++) for (j=i+1; j < toSort.length ; j++) if (toSort[j].compareTo(toSort[i])< 0) { String temp = toSort[i]; toSort[i] = toSort[j]; toSort[j] = temp; } } private static void sortF( String toSort[], File Path) { if (toSort.length<2) return; int i,j; for (i=0; i < toSort.length ; i++) { File fileA = new File( Path, toSort[i] ); for (j=i+1; j < toSort.length ; j++) { File fileB = new File( Path, toSort[j]); if ( (fileB.isDirectory() && fileA.isFile() ) || ( ((fileA.isDirectory() && fileB.isDirectory() ) || (fileA.isFile() && fileB.isFile()) ) && (toSort[j].compareTo(toSort[i])< 0) ) ) { String temp = toSort[i]; toSort[i] = toSort[j]; toSort[j] = temp; fileA = fileB; } } } } public void init() { setForeground( Color.black ); setBackground( Color.green ); } public void setOrder( boolean order ) { folderFirst = order; } public void setPath( String Path ) { if (Path==null) iconPath = ""; else iconPath = Path.replace('\\','/'); } public void save(String folder, String toFile) { PolicyEngine.assertPermission(PermissionID.SYSTEM); FileOutputStream saveFile = null; level = 0; try { saveFile = new FileOutputStream (toFile) ; DoIt( folder, new PrintStream( saveFile )); saveFile.close(); } catch (Exception e) {} } public static void main (String args[] ) { System.out.println("Content-type: text/html"); System.out.println(""); if (args.length < 1) { System.out.println("404 Not Given"); System.out.println("

404 Not Given

No path was requested.

"); return; } DoIt( cmdLine( args ), System.out ); } }